//
//  CrazyChatCustomListHeadView.m
//  webSocket
//
//  Created by 马军凯 on 2019/2/21.
//  Copyright © 2019 ZH. All rights reserved.
//

#import "CrazyChatCustomListHeadView.h"


@interface CrazyChatCustomListHeadView ()


@end

@implementation CrazyChatCustomListHeadView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = CRAZY_RGBR(242);
        
        NSArray *imageArray = @[@"CrazyChat_logistics@2x.png", @"CrazyChat_notice@2x.png", @"CrazyChat_discount@2x.png"];
        NSArray *nameArray = @[@"物流", @"通知", @"优惠"];
        NSArray *labelArray = @[self.logisticsLabel, self.noticeLabel, self.discountLabel];
        for (int i = 0; i < imageArray.count; i++) {
            //背景
            UIView *backView = [[UIView alloc] init];
            backView.frame = CGRectMake((self.width / imageArray.count) * i, 0, self.width / imageArray.count, self.height - 10);
            backView.backgroundColor = [UIColor whiteColor];
            [self addSubview:backView];
            //图片
            UIImageView *imageView = [[UIImageView alloc] init];
            imageView.frame = CGRectMake(backView.width / 2 - 22, 10, 44, 44);
            imageView.image = [UIImage imageNamed:imageArray[i]];
            [backView addSubview:imageView];
            //名称
            UILabel *nameLabel = [[UILabel alloc] init];
            nameLabel.frame = CGRectMake(5, 61, backView.width - 10, 15);
            nameLabel.text = nameArray[i];
            nameLabel.textColor = CRAZY_RGBR(55);
            nameLabel.textAlignment = NSTextAlignmentCenter;
            nameLabel.font = [UIFont systemFontOfSize:11];
            [backView addSubview:nameLabel];
            //数量
            UILabel *numLabel = labelArray[i];
            numLabel.frame = CGRectMake(imageView.width + imageView.x - 14, 9, 15, 15);
            [numLabel corner_radius:numLabel.height / 2];
            numLabel.hidden = YES;
            [backView addSubview:numLabel];
            //按钮
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = backView.bounds;
            btn.tag = 2000 + i;
            [btn addTarget:self action:@selector(clickCheckDetailBtn:) forControlEvents:UIControlEventTouchUpInside];
            [backView addSubview:btn];
        }
    }
    return self;
}

#pragma mark 查看详情
- (void)clickCheckDetailBtn:(UIButton *)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(CrazyChatSelectWithIndex:)]) {
        [self.delegate CrazyChatSelectWithIndex:sender.tag - 2000];
    }
}



#pragma mark 懒加载
//物流
- (UILabel *)logisticsLabel {
    if (_logisticsLabel == nil) {
        _logisticsLabel = [[UILabel alloc] init];
        _logisticsLabel.backgroundColor = [UIColor redColor];
        _logisticsLabel.textColor = [UIColor whiteColor];
        _logisticsLabel.textAlignment = NSTextAlignmentCenter;
        _logisticsLabel.font = [UIFont systemFontOfSize:8];
    }
    return _logisticsLabel;
}
//通知
- (UILabel *)noticeLabel {
    if (_noticeLabel == nil) {
        _noticeLabel = [[UILabel alloc] init];
        _noticeLabel.backgroundColor = [UIColor redColor];
        _noticeLabel.textColor = [UIColor whiteColor];
        _noticeLabel.textAlignment = NSTextAlignmentCenter;
        _noticeLabel.font = [UIFont systemFontOfSize:8];
    }
    return _noticeLabel;
}
//优惠
- (UILabel *)discountLabel {
    if (_discountLabel == nil) {
        _discountLabel = [[UILabel alloc] init];
        _discountLabel.backgroundColor = [UIColor redColor];
        _discountLabel.textColor = [UIColor whiteColor];
        _discountLabel.textAlignment = NSTextAlignmentCenter;
        _discountLabel.font = [UIFont systemFontOfSize:8];
    }
    return _discountLabel;
}







@end
